package com.css.fxfzxczh.modules.actionTrack.controller;

import com.alibaba.fastjson.JSONObject;

import com.css.fxfzxczh.base.response.RestResponse;
import com.css.fxfzxczh.modules.actionTrack.entity.ActionTrackEntity;
import com.css.fxfzxczh.modules.actionTrack.service.ActionTrackService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/actionTrack")
@Slf4j
public class ActionTrackController {
    @Autowired
    ActionTrackService actionTrackService;

    /***
     * 轨迹保存
     * @param actionTrackEntity
     * @return
     */
    @PostMapping("/save")
    public RestResponse save(@RequestBody ActionTrackEntity actionTrackEntity){
        RestResponse restResponse=null;
        JSONObject jsonObject=new JSONObject();
        try {
            actionTrackService.save(actionTrackEntity);
            jsonObject.put("message","保存成功");
            restResponse= RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "保存失败";
            }
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /***
     * 轨迹查看
     * @param userId,nowTime,xsemId
     * @return
     */
    @GetMapping("/getActionTracks")
    public RestResponse getActionTracks(String userId,String nowTime,String xsemId){
        RestResponse restResponse=null;
        try {
            List<ActionTrackEntity> ActionTrackS=actionTrackService.getActionTracks(userId,nowTime,xsemId);
            restResponse= RestResponse.succeed(ActionTrackS);
        }catch (Exception e){
            String errormessage="查看失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取所有现场采集人员的位置
     * @param
     * @return
     */
    @GetMapping("/getAllPersonnelPosition")
    public RestResponse getAllPersonnelPosition(String xsemId){
        RestResponse restResponse=null;
        try {
            List<ActionTrackEntity> list=actionTrackService.getAllPersonnelPosition(xsemId);
            restResponse= RestResponse.succeed(list);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取身为组长的现场采集人员的位置
     * @param
     * @return
     */
    @GetMapping("/getLeaderPosition")
    public RestResponse getLeaderPosition(String xsemId){
        RestResponse restResponse=null;
        try {
            List<ActionTrackEntity> list=actionTrackService.getLeaderPosition(xsemId);
            restResponse= RestResponse.succeed(list);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse= RestResponse.fail(errormessage);
        }
        return restResponse;
    }



}
